import 'package:json_annotation/json_annotation.dart';

part 'recipe.g.dart';

/// 食材信息
@JsonSerializable()
class RecipeMaterial {
  String type;
  String name;
  String amount;

  RecipeMaterial({required this.type, required this.name, required this.amount});

  factory RecipeMaterial.fromJson(Map<String, dynamic> json) =>
      _$RecipeMaterialFromJson(json);

  Map<String, dynamic> toJson() => _$RecipeMaterialToJson(this);
}

/// 步骤信息
@JsonSerializable()
class RecipeStep {
  int sort;
  String content;
  String imageUrl;

  RecipeStep({required this.sort, required this.content, required this.imageUrl});

  factory RecipeStep.fromJson(Map<String, dynamic> json) => _$RecipeStepFromJson(json);

  Map<String, dynamic> toJson() => _$RecipeStepToJson(this);
}

/// 评论信息
@JsonSerializable()
class RecipeComment {
  int id;
  String username;
  String avatar;
  String content;
  String date;

  RecipeComment({
    required this.id,
    required this.username,
    required this.avatar,
    required this.content,
    required this.date,
  });

  factory RecipeComment.fromJson(Map<String, dynamic> json) =>
      _$RecipeCommentFromJson(json);

  Map<String, dynamic> toJson() => _$RecipeCommentToJson(this);
}

/// 成果信息
@JsonSerializable()
class Record {
  int? id;
  String name;
  String category;
  int person;
  String date;
  String imageUrl;

  Record({
    this.id,
    required this.name,
    required this.category,
    required this.person,
    required this.date,
    required this.imageUrl,
  });

  factory Record.fromJson(Map<String, dynamic> json) => _$RecordFromJson(json);

  Map<String, dynamic> toJson() => _$RecordToJson(this);
}

@JsonSerializable()
class RecipeQuery {
  String category;

  RecipeQuery({
    required this.category
  });

  factory RecipeQuery.fromJson(Map<String, dynamic> json) => _$RecipeQueryFromJson(json);

  Map<String, dynamic> toJson() => _$RecipeQueryToJson(this);
}

/// 菜谱信息
@JsonSerializable()
class Recipe {
  int id;
  String name;
  String category;
  double recommendRate;
  String remark;
  bool isShare;
  int userId;
  String username;
  String avatar;
  List<RecipeMaterial> materialList;
  List<RecipeStep> stepList;
  List<Record> recordList;
  List<int> likeList;
  int likeCount;
  List<int> favouriteList;
  int favouriteCount;
  List<RecipeComment> commentList;
  int commentCount;

  Recipe({
    required this.id,
    required this.name,
    required this.category,
    required this.recommendRate,
    required this.remark,
    required this.isShare,
    required this.userId,
    required this.username,
    required this.avatar,
    required this.materialList,
    required this.stepList,
    required this.recordList,
    required this.likeList,
    required this.likeCount,
    required this.favouriteList,
    required this.favouriteCount,
    required this.commentList,
    required this.commentCount,
  });

  factory Recipe.fromJson(Map<String, dynamic> json) => _$RecipeFromJson(json);

  Map<String, dynamic> toJson() => _$RecipeToJson(this);
}

@JsonSerializable()
class RecipeSummary {
  int id;
  String name;
  String category;
  double recommendRate;
  bool isShare;
  List<Record> recordList;
  int likeCount;
  int favouriteCount;
  int commentCount;
  int userId;
  String username;
  String avatar;

  RecipeSummary({
    required this.id,
    required this.name,
    required this.category,
    required this.recommendRate,
    required this.isShare,
    required this.userId,
    required this.username,
    required this.avatar,
    required this.recordList,
    required this.likeCount,
    required this.favouriteCount,
    required this.commentCount,
  });

  factory RecipeSummary.fromJson(Map<String, dynamic> json) => _$RecipeSummaryFromJson(json);

  Map<String, dynamic> toJson() => _$RecipeSummaryToJson(this);
}

@JsonSerializable()
class RecipeDetail {
  int id;
  String name;
  String category;
  double recommendRate;
  String remark;
  bool isShare;
  int userId;
  String username;
  String avatar;
  List<RecipeMaterial> materialList;
  List<RecipeStep> stepList;
  List<Record> recordList;
  List<int> likeList;
  List<int> favouriteList;
  List<RecipeComment> commentList;

  RecipeDetail({
    required this.id,
    required this.name,
    required this.category,
    required this.recommendRate,
    required this.remark,
    required this.isShare,
    required this.userId,
    required this.username,
    required this.avatar,
    required this.materialList,
    required this.stepList,
    required this.recordList,
    required this.likeList,
    required this.favouriteList,
    required this.commentList,
  });

  factory RecipeDetail.fromJson(Map<String, dynamic> json) => _$RecipeDetailFromJson(json);

  Map<String, dynamic> toJson() => _$RecipeDetailToJson(this);
}

enum ViewType { recipe, calendar, timeline }
